package com.zyk.leetcode;

import java.util.HashSet;

/**
 * @author zhangsan
 * @date 2021/5/4 18:03
 */
public class C1593 {

    public static int maxUniqueSplit(String s) {
        return process(0, 0, s.toCharArray(), new HashSet<>());
    }

    public static int process(int index, int split, char[] str, HashSet<String> set) {
        if (index == str.length) return split;
        StringBuilder sb = new StringBuilder();
        int ways = -1;
        for (int i = index; i < str.length; i++) {
            sb.append(str[i]);
            String subStr = sb.toString();
            if (!set.contains(subStr)) {
                set.add(subStr);
                ways = Math.max(ways, process(index + sb.length(), split + 1, str, set));
                set.remove(subStr);
            }
        }
        return ways;
    }



    // for test
    public static void main(String[] args) {
        String s = "eehe";
        System.out.println(maxUniqueSplit(s));


        /*int times = 100000;
        int maxLend = 5;
        System.out.println("测试开始.");
        for (int i = 0; i < times; i++) {
            String s = generateString(maxLend);
            int ans1 = maxUniqueSplit(s);
            int ans2 = maxUniqueSplit2(s);
            if(ans1 != ans2) {
                System.out.println("OOPS!");
                System.out.println(s);
                System.out.println(ans1);
                System.out.println(ans2);
                break;
            }
        }
        System.out.println("测试结束!");*/
    }

    public static String generateString(int maxLen) {
        maxLen = (int) (Math.random() * maxLen);
        char[] str = new char[maxLen];
        for (int i = 0; i < maxLen; i++) {
            str[i] = (char) (Math.random() * 10 + 'a');
        }
        return new String(str);
    }

}
